//
//  LJProjectTags.m
//
//  Created by   on 2018/9/28
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "LJProjectTags.h"


NSString *const kLJProjectTagsIsShow = @"is_show";
NSString *const kLJProjectTagsFilterTag = @"filter_tag";
NSString *const kLJProjectTagsSearchTag = @"search_tag";
NSString *const kLJProjectTagsShowWeight = @"show_weight";
NSString *const kLJProjectTagsDesc = @"desc";
NSString *const kLJProjectTagsColor = @"color";


@interface LJProjectTags ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation LJProjectTags

@synthesize isShow = _isShow;
@synthesize filterTag = _filterTag;
@synthesize searchTag = _searchTag;
@synthesize showWeight = _showWeight;
@synthesize desc = _desc;
@synthesize color = _color;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.isShow = [self objectOrNilForKey:kLJProjectTagsIsShow fromDictionary:dict];
            self.filterTag = [self objectOrNilForKey:kLJProjectTagsFilterTag fromDictionary:dict];
            self.searchTag = [self objectOrNilForKey:kLJProjectTagsSearchTag fromDictionary:dict];
            self.showWeight = [self objectOrNilForKey:kLJProjectTagsShowWeight fromDictionary:dict];
            self.desc = [self objectOrNilForKey:kLJProjectTagsDesc fromDictionary:dict];
            self.color = [self objectOrNilForKey:kLJProjectTagsColor fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.isShow forKey:kLJProjectTagsIsShow];
    [mutableDict setValue:self.filterTag forKey:kLJProjectTagsFilterTag];
    [mutableDict setValue:self.searchTag forKey:kLJProjectTagsSearchTag];
    [mutableDict setValue:self.showWeight forKey:kLJProjectTagsShowWeight];
    [mutableDict setValue:self.desc forKey:kLJProjectTagsDesc];
    [mutableDict setValue:self.color forKey:kLJProjectTagsColor];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.isShow = [aDecoder decodeObjectForKey:kLJProjectTagsIsShow];
    self.filterTag = [aDecoder decodeObjectForKey:kLJProjectTagsFilterTag];
    self.searchTag = [aDecoder decodeObjectForKey:kLJProjectTagsSearchTag];
    self.showWeight = [aDecoder decodeObjectForKey:kLJProjectTagsShowWeight];
    self.desc = [aDecoder decodeObjectForKey:kLJProjectTagsDesc];
    self.color = [aDecoder decodeObjectForKey:kLJProjectTagsColor];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_isShow forKey:kLJProjectTagsIsShow];
    [aCoder encodeObject:_filterTag forKey:kLJProjectTagsFilterTag];
    [aCoder encodeObject:_searchTag forKey:kLJProjectTagsSearchTag];
    [aCoder encodeObject:_showWeight forKey:kLJProjectTagsShowWeight];
    [aCoder encodeObject:_desc forKey:kLJProjectTagsDesc];
    [aCoder encodeObject:_color forKey:kLJProjectTagsColor];
}

- (id)copyWithZone:(NSZone *)zone {
    LJProjectTags *copy = [[LJProjectTags alloc] init];
    
    
    
    if (copy) {

        copy.isShow = [self.isShow copyWithZone:zone];
        copy.filterTag = [self.filterTag copyWithZone:zone];
        copy.searchTag = [self.searchTag copyWithZone:zone];
        copy.showWeight = [self.showWeight copyWithZone:zone];
        copy.desc = [self.desc copyWithZone:zone];
        copy.color = [self.color copyWithZone:zone];
    }
    
    return copy;
}


@end
